package com.rh.number.mapper;

import com.rh.number.entity.UserinfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

@Mapper
public interface UserinfoMapper {
    UserinfoEntity selectByUsername(String username);
    int insert(UserinfoEntity user);
    @Select("SELECT COUNT(*) FROM userinfo")
    int countUsers();

    // 根据ID查询用户
    @Select("SELECT * FROM userinfo WHERE id = #{id}")
    Optional<UserinfoEntity> findById(Long id);

    // 根据用户名查询用户
    @Select("SELECT * FROM userinfo WHERE username = #{username}")
    Optional<UserinfoEntity> findByUsername(String username);

    // 更新密码
    void updatePassword(@Param("id") Long id, @Param("newPassword") String newPassword);

    // 更新角色
    void updateRoleById(@Param("id") Long id, @Param("newRole") Integer newRole);
}